<?php
/* 
 *运费管理
 */
class LogifeeAction extends TransAction {
    public function _filter(&$map) {
        $key = trim($_REQUEST['keywords']);
        if(!empty($key)) { //仅按货物明细搜索即可
            $where['logi_no'] = array('like',"%".$key."%");
            $where['Order_detail.mano'] = array('like',"%".$key."%");
            $where['Shipping.mano'] = array('like',"%".$key."%");
            $where['Product.name'] = array('like',"%".$key."%");
            $where['Product.ename'] = array('like',"%".$key."%");
            $where['Product.cas'] = array('like',"%".$key."%");
            $where['_logic'] = "or";
            $map['_complex'] = $where;
        }
        if(!empty($_REQUEST['customer']))
            $map['_string'] = "(Customer.name like '%".$_REQUEST['customer']."%') or (Customer.company like '%".$_REQUEST['customer']."%')";
        if(isset($_REQUEST['logi_id']) && $_REQUEST['logi_id'] != ''  )
            $map['logi_id'] = intval($_REQUEST['logi_id']);

        
    }

    public function index()
    {//列表过滤器，生成查询Map对象
        $map = $this->_search ();
        if (method_exists ( $this, '_filter' )) {
            $this->_filter ( $map );
        }
        
        $model = D ('ShippingOrderDetailView');
        if (! empty ( $model )) {
            $this->_list ( $model, $map,'',false,true );//group 去掉重复数据
        }
        $this->display ();
        return;
        //parent::index('ShippingOrderDetailView');
    }

     public function edit(){
        $model = M ( 'Shipping');
        $id = $_REQUEST [$model->getPk ()];
        if(isset($id)){
            $vo = $model->where('id = '.$id )->find();
            $this->assign ( 'vo', $vo );
            $map = array(
                'shipping_id' => $vo['id'],
             );
            $sum_logifee = D('ShippingDetailOrderDetailView')->where('Shipping.order_id = '.$vo['order_id'] )->sum('logifee');
            $ps = M('Shipping_detail')->where($map )->order('id desc')->findAll(); 
            
            $this->assign('products',$ps);
            $this->assign('us_logifee',$sum_logifee); //暂时默认为US $
            $this->display ();
        }
    }

     public function update()
    {
        A('Shipping')->update();
    }

}
?>
